home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Extra 1997 #1 / Amiga Plus Extra 1997 #1.iso / programme / daten / stringer11 / stringer.doc < prev    next >
Encoding:
Text File  |  1984-11-14  |  20.0 KB  |  572 lines

  1.  
  2. Stringer v1.1 © 1996 by Henri Veisterä
  3. ======================================
  4. --------------------------------------
  5.  
  6.  
  7. 0.0 Document Index
  8. ==================
  9.  
  10. 1.0 Overview
  11.     1.1 Requirements
  12.     1.2 The Story
  13. 2.0 Usage
  14.     2.1 Command line options
  15.     2.2 Output control
  16.     2.3 Script file usage
  17.     2.4 Preferences
  18. 3.0 Example command lines
  19.     3.1 Example 1 - Vanilla
  20.     3.2 Example 2 - Multiple strings
  21.     3.3 Example 3 - A quick scan
  22.     3.4 Example 4 - Complex patterns
  23.     3.5 Example 5 - Statistics
  24.     3.6 Example 6 - Hunt files
  25.     3.6 Example 7 - Relative frequencies
  26. 4.0 The test section
  27.     4.1 Test 1 - Algorithm test
  28.     4.2 Test 2 - Multiple small file test
  29.     4.3 Test 3 - Multiple large file test
  30.     4.4 Test 4 - Multiple string test
  31.     4.5 Grande Test Total
  32.     4.6 Buffer effeciency graph
  33. 5.0 Author and support
  34. 6.0 Version history
  35.  
  36.  
  37.  
  38. 1.0 Overview
  39. ============
  40.  
  41. 1.1 Requirements
  42. ----------------
  43.  
  44. Stringer needs AmigaOS 2.1 (V37) or later and a minimum of 18 kb's of free
  45. mem to operate.  Stringer is pure and can be made resident.
  46.  
  47.  
  48. 1.2 The Story
  49. -------------
  50.  
  51. Yes, yet another Search replacement ...  with bells on it.  As it happens,
  52. I wrote this purely for my own usage and amusement and was surprised to see
  53. that there were so many similar utils already out there.  This one started
  54. its life as a tool for counting strings, mainly very short strings (as in
  55. counting the relative frequencies of the alphabets) and it just grew from
  56. there.
  57.  
  58. What then makes this one oh, so special ?  Why should _YOU_ switch
  59. immediately to Stringer ?  Well, it's the fastest one around (see the test
  60. section).  Stringer is a complete in-place replacement for Search emulating
  61. _every_ function of Search with identical output (if the user so desires).
  62. Stringer specializes in searching for multiple strings.  The strings can be
  63. of any size, there can be any number of strings, the strings can be read
  64. from a file and the strings can be substrings of other strings searched
  65. for.  If you frequently search for multiple words for whatever reason, no
  66. other util comes near in speed and in ease of use.
  67.  
  68. Stringer also has another use than just as a fancy replacement for Search.
  69. It displays statistical information on the matched strings.  Their match
  70. counts, relative space usage and relative frequencies.
  71.  
  72.  
  73.  
  74. 2.0 Usage
  75. =========
  76.  
  77. Stringer is run from the CLI with the basic command line looking like this:
  78.  
  79. Stringer SOURCEFILES STRINGS [OPTIONS]
  80.  
  81. Stringer behaves exactly like Search with its default options so you can
  82. immediately use it as you did Search before.
  83.  
  84.  
  85. 2.1 Command line options
  86. ------------------------
  87.  
  88. The full command line usage is as follows:
  89.  
  90. FROM/M/A     - Source files to search from
  91. SEARCH/A     - Strings to search or a file name containing the strings
  92.                Separate strings with "," in CLI or "<CR>" in a file
  93. B=BUFFER/K/N - Work buffer size in kilobytes, defaults to 100 kb
  94. C=CASE/S     - Case sensitive search
  95. N=NONUMS/S   - No line numbering
  96. V=VERBOSE/S  - Show file size and number and size of strings
  97. T=SHOWTIME/S - Show elapsed time
  98. S=STATS/S    - Display search statistics
  99. L=NOLINES/S  - Don't show lines were a match was found
  100. A=ALL/S      - Recursively scan the file tree
  101. M=MATCHES/S  - Show number of matches in current file
  102. Q=QUICK/S    - Less CR's in the CLI output
  103. I=INVERT/S   - Show lines that do not match the search criteria
  104. P=PATTERN/S  - SEARCH is an AmigaDOS pattern
  105. F=FILE/S     - Hunt for a filename, SEARCH=filename to search for
  106. O=ONLY/S     - Show only names of files where a match was found
  107. BIN/S        - Force Stringer to search through binary files.
  108. ANSI/S       - Highlight matched string in the output
  109. MAXHIT/K/N   - Give up on a file when MAXHIT matches are found
  110. QUIET/S      - No output to CLI, only a result code
  111. FILECOL/K/N  - Color for filenames (a pen number from 0 to n)
  112. HITCOL/K/N   - Color for a matched string (a pen number from 0 to n)
  113. STRFILE/S    - Load strings from a file, SEARCH=filename
  114. NOPREFS/S    - Ignore ENV:Stringer.prefs
  115.  
  116. Yeah, I know, all the stuff in Search, Grep and FlashFind crammed into one
  117. and then some more.  See the command line examples for more indepth reviews
  118. of the options.
  119.  
  120.  
  121. 2.2 Output control
  122. ------------------
  123.  
  124. Specifying the L=NOLINES option means that you won't get any output on your
  125. screen.  So, use it only in combination with the M=MATCHES and/or S=STATS
  126. options.  Using the QUIET option, you won't get any output at all except
  127. the error messages.  Not even the filenames.  Using the O=ONLY option
  128. displays only the file names where a match was found so, in effect, this is
  129. the same as specifying L=NOLINES, M=MATCHES and Q=QUICK, the output,
  130. however, looks different in each case.
  131.  
  132. Use the ANSI option to add some color to your output.  You can control the
  133. colors with the FILECOL and HITCOL options.
  134.  
  135. Note that if you use the MAXHIT and S=STATS options together the stats
  136. won't be correct since the search is aborted when MAXHIT hits are found.
  137. MAXHIT is ignored if the option L=NOLINES is on (as it should be on, when
  138. you want to see the statistics).
  139.  
  140. While Stringer is running you can abort the search with CTRL-C or you can
  141. skip the current file with CTRL-D.
  142.  
  143.  
  144. 2.3 Script file usage
  145. ---------------------
  146.  
  147. Stringer exits with these return codes:
  148. 0 = One or more match found
  149. 5 = No matches found
  150. 20 = A fatal error occured
  151.  
  152. Use Stringer in a script file like this:
  153.  
  154. --- AmigaDOS script file ---
  155. Stringer Text.doc PoroJesse QUIET
  156.  
  157. If warn
  158.     Echo "Didn't find PoroJesse in Text.doc."
  159. Else
  160.     Echo "Found the string PoroJesse in Text.doc !"
  161. EndIf
  162. --- AmigaDOS script file ---
  163.  
  164.  
  165. 2.4 Preferences
  166. ---------------
  167.  
  168. Stringer reads your preferences from a file called ENV:Stringer.prefs.
  169. These options are read in first and thus your command line options are
  170. 'added' to these.  To temporarily disable the prefs use the command line
  171. option NOPREFS.
  172.  
  173. To set your preferences for Stringer do this in CLI:
  174.  
  175. Setenv Stringer ANSI MAXHIT=200 QUICK BUFFER=400
  176.  
  177. To make these prefs permanent do this:
  178.  
  179. Copy ENV:Stringer.prefs ENVARC:Stringer.prefs
  180.  
  181.  
  182.  
  183. 3.0 Example command lines
  184. =========================
  185.  
  186. 3.1 Example 1
  187. -------------
  188.  
  189. Stringer Include/#? ggi_RastPort ALL
  190.  
  191. Straight forward stuff ...  walk through the Include directories searching
  192. for the string ggi_RastPort.  The search is not case sensitive.  This will
  193. produce the same output as using the C:  command Search.  Only a bit
  194. faster.
  195.  
  196.  
  197. 3.2 Example 2
  198. -------------
  199.  
  200. Stringer #?new#?.txt "STRING ONE,STRING TWO"
  201.  
  202. This example shows the quick way to search for multiple strings from
  203. multiple files.  The strings include spaces so they are enclosed in quotes.
  204. Each string is separated with a comma.  If you want to search for a string
  205. that includes a comma use two commas in a row :  "like I said,, then"
  206.  
  207.  
  208. 3.3 Example 3
  209. -------------
  210.  
  211. Stringer dh0:sc/include/#? ALL SEARCH=select B=500 CASE QUICK L M
  212.  
  213. Here we have a quick scan of all the files in this directory and all its
  214. child directories.  We scan for the word 'select' and the final output will
  215. only show the names of the files where the string was found and a count of
  216. matches.  The name of the file we currently scan is shown but erased by the
  217. next name.  Like this:
  218.  
  219. --- Stringer Output ---
  220. HDisk0:sc/include/intuition/imageclass.h
  221.  2 matches
  222. HDisk0:sc/include/intuition/intuition.h
  223.  22 matches
  224. HDisk0:sc/include/intuition/preferences.h
  225.  2 matches
  226. HDisk0:sc/include/intuition/screens.h
  227.  1 matches
  228. HDisk0:sc/include/libraries/asl.h
  229.  5 matches
  230. HDisk0:sc/include/libraries/gadtools.h
  231.  4 matches
  232. HDisk0:sc/include/libraries/diskfonttag.h
  233.  2 matches
  234. HDisk0:sc/include/resources/battmembitsamiga.h
  235.  2 matches
  236. --- Stringer Output ---
  237.  
  238.  
  239. 3.4 Example 4
  240. -------------
  241.  
  242. Stringer FROM imageclass.h SEARCH=#?0x0[0-9A-F]L#? PATTERN
  243.  
  244. If you want to search for a complex AmigaDOS pattern use the option
  245. PATTERN.  Note that there is no sense in using a pattern like
  246. SEARCH=(#?keput#?|#?sossut#?) since SEARCH=keput,sossut without the option
  247. PATTERN will give the same result and much faster.  In this example we look
  248. for lines that include an ascii hex number from 0x00L to 0x0FL.  Note too
  249. that the option CASE aplies here also.  And a final note:  the pattern is
  250. matched against each line in the source file, meaning that a pattern
  251. SEARCH=timeout would only match a line that contains nothing but the word
  252. timeout.
  253.  
  254. Here's how to make up an AmigaDOS pattern: 
  255.  
  256. --- illegally/without permission quoted from the autodocs ---
  257.  
  258.     The patterns are fairly extensive, and approximate some of the ability
  259.     of Unix/grep "regular expression" patterns.  Here are the available
  260.     tokens:
  261.  
  262.     ?    Matches a single character.
  263.     #    Matches the following expression 0 or more times.
  264.     (ab|cd)    Matches any one of the items seperated by '|'.
  265.     ~    Negates the following expression.  It matches all strings
  266.         that do not match the expression (aka ~(foo) matches all
  267.         strings that are not exactly "foo").
  268.     [abc]    Character class: matches any of the characters in the class.
  269.     a-z    Character range (only within character classes). 
  270.     %    Matches 0 characters always (useful in "(foo|bar|%)").
  271.     *    Synonym for "#?", not available by default in 2.0.  Available
  272.         as an option that can be turned on.
  273.  
  274.     "Expression" in the above table means either a single character
  275.     (ex: "#?"), or an alternation (ex: "#(ab|cd|ef)"), or a character
  276.     class (ex: "#[a-zA-Z]").
  277.  
  278. --- illegally/without permission quoted from the autodocs ---
  279.  
  280.  
  281. 3.5 Example 5
  282. -------------
  283.  
  284. Stringer Text.txt Strings.txt STRFILE B 300 C V T S L
  285.  
  286. This is a typical statistical output command line.  You get output looking
  287. quite different from Search.  We go through Text.txt looking for the
  288. strings in the file Strings.txt.  Strings.txt might look like this:
  289.  
  290. String1
  291. Stringer2
  292. Str3
  293.  
  294. So, it's a text file where the strings are separated with CR's.  Internal
  295. buffer used is 300 kilobytes in size, matching is case sensitive, you'll
  296. see the file size and the number of strings in the file Strings.txt and
  297. their collective size.  You will see something like this:
  298.  
  299. --- Stringer Output ---
  300. Searching 1801657 bytes of data for 3 strings (total 20 bytes) ...
  301. String                                             Hits   All Relat
  302. '                                  String1'       95889    53   964
  303. '                                Stringer2'        2557     5    25
  304. '                                     Str3'        1001     2    10
  305. -------------------------------------------------------------------
  306. TOTAL:                           3 strings        99447    60  1000
  307. Time elapsed: 10 secs (7411549 ticks, 709379 ticks/sec)
  308. --- Stringer Output ---
  309.  
  310. This tells you the following:
  311.  
  312. String1 occurs 95889 (Hits column) times in the text, 96.4 (Relat column)
  313. percent of the matched strings were String1.  String1 makes up 5.3 (All
  314. column) percent of the whole text.
  315.  
  316. Stringer2 occurs 2557 times in the text, 2.5 % of the matched strings were
  317. String2.  Stringer2 takes up approx.  9000 bytes (= 0.005 * 1801657) of the
  318. 1801657 bytes in the whole file.
  319.  
  320. Str3 occurs 1001 times in the text, 1.0 % of the matched strings were Str3.
  321.  
  322. The TOTAL line gives the added sums of all the above.  The whole operation
  323. took 10 seconds.
  324.  
  325.  
  326. 3.6 Example 6
  327. -------------
  328.  
  329. Stringer DH0: DH1: DH2: #?.txt ALL FILE
  330.  
  331. Hunt volumes DH0: , DH1: and DH2: for any files that end in letters .txt .
  332. This quickly scans the whole directory structure of the three volumes above
  333. and displays any files found matching the search criteria.
  334.  
  335.  
  336. 3.7 Example 7
  337. -------------
  338.  
  339. Stringer bigtext.txt a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z L S >strout.txt
  340.  
  341. Go through the file bigtext.txt and count all the alphabets in the text.
  342. Output statistics to a file called strout.txt.
  343.  
  344. Sort FROM strout.txt TO sorted.txt COLSTART 45 NUMERIC 
  345.  
  346. Use the AmigaDOS command Sort and you get output like this (file sorted.txt):
  347.  
  348. --- Stringer Output ---
  349. String                                             Hits   All Relat
  350. '                                        Z'        1397     0     1
  351. '                                        Q'        1425     0     1
  352. '                                        X'        3849     2     3
  353. '                                        J'        5831     3     5
  354. '                                        V'        9807     6     8
  355. '                                        B'       17773    10    16
  356. '                                        P'       19669    12    17
  357. '                                        W'       19748    12    17
  358. '                                        F'       21239    13    19
  359. '                                        K'       21733    13    19
  360. '                                        G'       22208    13    20
  361. '                                        Y'       23191    14    20
  362. '                                        M'       32917    20    29
  363. '                                        C'       35719    21    32
  364. '                                        L'       38968    23    35
  365. '                                        U'       39221    24    35
  366. '                                        D'       40567    24    36
  367. '                                        H'       48059    29    43
  368. '                                        R'       64312    39    57
  369. '                                        S'       70609    43    63
  370. '                                        N'       77408    47    69
  371. '                                        I'       80250    49    72
  372. '                                        O'       84288    51    76
  373. '                                        T'       99484    61    89
  374. '                                        A'      102745    63    92
  375. '                                        E'      126617    77   114
  376. -------------------------------------------------------------------
  377. TOTAL:                          26 strings      1109034   669  1000
  378. --- Stringer Output ---
  379.  
  380. If the file bigtext.txt was an ascii text file in English you can see from
  381. the above the relative frequencies of the alphabets in the English language
  382. (or a good approximation of it).  There is a 6.9 percent propability that
  383. the next letter you see is the letter 'N'.  The most common letter is the
  384. letter 'E'.
  385.  
  386.  
  387.  
  388. 4.0 The test section
  389. ====================
  390.  
  391. I spent a day compiling this stuff, so you better read it through.  A quick
  392. summary can be found at the end of this section.  In all the tests I
  393. experimented with different command line options to get the best results,
  394. any output was redirected to NIL:.  Since some of the utils don't support
  395. searching multiple files, multiple directories or multiple strings script
  396. files were created for these utils where they were just executed a multiple
  397. of times.
  398.  
  399. Test hardware:
  400. 68030/28 Mhz, 4 MB/32 bit Mem, Seagate 501 MB SCSI-2 HD, OS3.1
  401.  
  402. Test software:
  403. Search 40.1   by AmigaDOS
  404. ssearch 1.4   by Stefan Sticht
  405. FSearch 1.2   by Edwin H. Bielawski
  406. ZSearch 1.0c  by Alessandro Zummo, 030 version used
  407. FlashFind 1.2 by Frank Würkner
  408. Stringer 1.1  by Henri Veisterä
  409.  
  410.  
  411. 4.1 Test 1
  412. ----------
  413.  
  414. Source file is 1801657 bytes of ascii text with variable line lengths.
  415. Search one string (strlen = 7 bytes) case sensitive from RamDisk.  The
  416. string is found two times in the source file.
  417.  
  418. Util      Time/s  RelSpeed 
  419.  
  420. search      92.9      84.5
  421. fsearch     15.3      13.9
  422. ssearch     11.1      10.1
  423. zsearch      3.7       3.4
  424. flashfind    1.1       1.0
  425. stringer     1.1       1.0
  426.  
  427. This is a test of just the search algorithms, file access times are minimal
  428. here.  FlashFind looses by a few hundreths of a second.
  429.  
  430.  
  431. 4.2 Test 2
  432. ----------
  433.  
  434. Source files are the Commodore assembler include files 218 files - 16 dirs
  435. - 871692 bytes.  Searching for one string 11 bytes in size which is found
  436. three times in one of the source files.  Search is case sensitive from a
  437. hard drive.
  438.  
  439. Util      Time/s  RelSpeed 
  440.  
  441. search      99.2       4.3
  442. fsearch     57.1       2.5
  443. zsearch      n/a,47.1  2.0
  444. ssearch     41.9       1.8
  445. flashfind   35.9       1.6
  446. stringer    23.0       1.0
  447.  
  448. Lots of small files (average file size ~4000 bytes) to go through so the
  449. importance of the search algorithm is less here, a large portion of the
  450. time is spent loading the files.  Stringer wins through efficient multiple
  451. file implementation.  ZSearch can't search multiple files so the time here
  452. is from a script file created for this test.
  453.  
  454.  
  455. 4.3 Test 3
  456. ----------
  457.  
  458. Commodore AutoDocs 30 files - 1768252 bytes.  Searching for one string
  459. (7 bytes).  String is found 47 times in the source files.  Search is
  460. case sensitive from a hard drive.
  461.  
  462. Util      Time/s  RelSpeed 
  463.  
  464. search     159.8      24.2
  465. ssearch     63.4       9.6
  466. fsearch     63.0       9.5
  467. flashfind   52.7       8.0
  468. zsearch      n/a,14.4  2.2
  469. stringer     6.6       1.0
  470.  
  471. Stringer really shines through here.  Easily the fastest 8-P.
  472.  
  473.  
  474. 4.4 Test 4 - The really unfair test =)
  475. --------------------------------------
  476.  
  477. Commodore AutoDocs 30 files - 1768252 bytes.  Searching for three strings
  478. (20 bytes).  Strings are found 375 times in the source files.  Search is
  479. not case sensitive and from a hard drive.
  480.  
  481. search     554.2          38.5
  482. fsearch      n/a,202.6    14.1
  483. ssearch      n/a,195.7    13.6
  484. flashfind  353.1,159.1    11.0
  485. zsearch      n/a,43.9      3.0
  486. stringer    14.4           1.0
  487.  
  488. As you can see, this is why I made Stringer in the first place so it should
  489. show here ...  and it does :-!  Only Stringer, FlashFind and Search have
  490. the capability to search for multiple strings.  All the results after the
  491. commas are from script files created for this test.
  492.  
  493.  
  494. 4.5 Grande Test Total
  495. ---------------------
  496.  
  497.            Test1         Test2         Test3         Test4         Total
  498.          Time/s   Rel  Time/s   Rel  Time/s   Rel  Time/s   Rel  Time/s   Rel
  499.  
  500. search     92.9  84.5    99.2   4.3   159.8  24.2   554.2  38.5   906.1  20.1
  501. fsearch    15.3  13.9    57.1   2.5    63.0   9.6   202.6+ 14.1   338.0   7.5
  502. ssearch    11.1  10.1    41.9   2.0    63.4   9.5   195.7+ 13.6   312.1   6.9
  503. flashfind   1.1   1.0    35.9   1.8    52.7   8.0   159.1+ 11.0   248.8   5.5
  504. zsearch     3.7   3.4    47.1   1.6    14.4+  2.2    43.9+  3.0   109.1   2.4
  505. stringer    1.1   1.0*   23.0   1.0*    6.6   1.0*   14.4   1.0*   45.1   1.0
  506.  
  507. A * marks the best result, a + means that the util didn't support this test
  508. and a script file was used instead.
  509.  
  510. So, twice as fast as the nearest contender ...  but since zsearch is really
  511. limited in its uses I could say 5 to 20 times as fast as the rest !  Most
  512. pleasing for me is that Stringer is at its best at just the kind of work I
  513. use a string searcher for (tests 3 and 4).  Curiosly enough, the only util
  514. whose search algorithm is more powerful than Stringers (FlashFind is faster
  515. when strlen > 7) fails totally in real world performance.  I suspect this
  516. has to do with faulty a-sync IO routines.
  517.  
  518.  
  519. 4.6 Buffer effeciency graph
  520. ---------------------------
  521.  
  522. No test section would be complete without a beatiful graph.  Thus, for your
  523. enjoyment:  the following graph represents the time spent searching for one
  524. string from a 1759 kb source file with varying buffer sizes.
  525.  
  526. 1.80    .*
  527. 1.75   .  ·
  528. 1.70  *    .
  529. 1.65       *
  530. 1.60        ·                 *·.
  531. 1.55        *                .   *·.
  532. 1.50         .      .*.             *
  533. 1.45          ·*··*·   .
  534. 1.40                    *   .        .
  535. 1.35                     .
  536. 1.30                      .           .
  537. 1.25                       .
  538. 1.20                       *           *··*··*··*··*··*·.
  539. 1.15                                                     *··*
  540. 1.10 
  541.       1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19
  542.  
  543. On the y-axis is the elapsed time in seconds and on the x-axis is the
  544. buffer size used in 100 kilobytes.  The asterisks '*' are measured data
  545. points and the points '·' in between were interpolated.
  546.  
  547. From this you can see that after 1200 kb's the usefullness of a greater
  548. buffer size is dubious.  Note that the low points are situated at 400 kb
  549. intervals due to exec.librarys internal optimizations.  So, in other words,
  550. if you want to use a greater default buffer size use 400, 800 or 1200 kb's.
  551.  
  552.  
  553.  
  554. 5.0 Author and support
  555. ======================
  556.  
  557. Stringer was written in 100% Assembler by me, Henri Veisterä.  For bug
  558. reports, fan/hate-mail or general chit-chat you can contact me through the
  559. net via:  hveister@snakemail.hut.fi .  Stringer is Freeware.  Give it away,
  560. don't sell it.  Latest version will always be posted to AmiNet.
  561.  
  562.  
  563.  
  564. 6.0 Version history
  565. ===================
  566.  
  567. Version 1.0 - 26-Jun-93 ... Ancient stats shower
  568.  
  569. Version 1.1 - 16-Aug-96 ... First public release
  570.  
  571.  
  572.